//
//  RNOLMessageDNDViewController.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/11.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLMessageDNDViewController.h"
#import "RNOLSettingSwitchCell.h"

@interface RNOLMessageDNDViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSDictionary *dataDict;

@end

@implementation RNOLMessageDNDViewController

- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH , KHIGHT) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = kBgColor;
        adjustsScrollViewInsets_NO(_tableView, self);
//        _tableView.height -= kBottomHeight;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone ;
        UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH , 10)];
        [_tableView registerNib:[UINib nibWithNibName:@"RNOLSettingSwitchCell" bundle:nil] forCellReuseIdentifier:@"RNOLSettingSwitchCell"];
        header.backgroundColor = kBgColor;
        _tableView.tableHeaderView = header;
        _tableView.tableFooterView = [UIView new];
        [self.view addSubview: _tableView];
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kBgColor;
    [self setupNavBarTitleViewWithText:@"功能消息免打扰"];
    [self setup];
}


- (void)setup{
    self.dataDict = @{
                      @"0" : @[@"开启免打扰"],
                      @"1" : @[@"只在夜间开启"],
                      @"2" : @[@"活动推送"]
                      };
    [self.tableView reloadData];
}


#pragma mark -  UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [self.dataDict.allKeys count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *items = self.dataDict[@(section).stringValue];
    return items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *items = self.dataDict[@(indexPath.section).stringValue];
        RNOLSettingSwitchCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RNOLSettingSwitchCell"];
        cell.headlineTitleLabel.text = items[indexPath.row];
    cell.couponInfoLabel.hidden = indexPath.section != 2;
        return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return indexPath.section == 2?  70 : 50;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 1 ) {
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH , 30)];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, KWIDTH - 30, 30)];
        label.textColor = kTextColor ;
        label.font = KFontSize(12);
        label.text = @"如果设置为“只在夜间开启”，则只在22:00至8:00间生效";
        [bgView addSubview: label];
        return bgView;
    }else{
        return [UIView new];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if ( 1 == section) {
        return 30;
    }else{
        return 5;
    }
}

@end
